import * as server from "@minecraft/server";
import * as data_entity from "../data/entity";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
export class EnchantedEquipmentTrigger extends achieve_plan.Template {
    Trigger(player) {
        const equippable = player.getComponent('minecraft:equippable');
        const itemSlot = Object.values(server.EquipmentSlot);
        itemSlot.map(slot => equippable?.getEquipment(slot)).forEach((item, index) => {
            switch (item?.typeId) {
                case 'item_equipment:purple_gold_soul_jade':
                    PurpleGoldSoulJade(player, item, itemSlot[index], equippable);
                    break;
                case 'item_equipment:scarlet_flame_heart':
                    ScarletFlameHeart(player, item, itemSlot[index], equippable);
                    break;
                case 'item_equipment:starry_night_bead':
                    StarryNightBead(player, item, itemSlot[index], equippable);
                    break;
                case 'item_equipment:ice_essence_gem':
                    IceEssenceGem(player, item, itemSlot[index], equippable);
                    break;
                case 'item_equipment:azure_sea_tide':
                    AzureSeaTide(player, item, itemSlot[index], equippable);
                    break;
                case 'item_tool:magic_crystal_shield':
                    MagicCrystalShield(player);
                    break;
                case 'item_armor:seas_in_ring':
                    SeasInRing(player);
                    break;
                default: break;
            }
        });
    }
    ;
    afterPlanEvent() {
        const players = server.world.getAllPlayers();
        players.forEach(player => this.Trigger(player));
    }
    ;
    static BriefCreate(nameTag) {
        return this.Create(nameTag, 100, {});
    }
    ;
}
;
function SeasInRing(player) {
    const options = {
        excludeFamilies: ['monster'],
        location: player.location,
        maxDistance: 8,
        closest: 8
    };
    const onSort = (entity0, entity1) => {
        const distance0 = math_tools.Vector.distance(player.location, entity0.location);
        const distance1 = math_tools.Vector.distance(player.location, entity1.location);
        return distance0 - distance1;
    };
    const onFilter = (target) => {
        return target.id === player.id || target.getDynamicProperty('entity:contract_user') == player.id;
    };
    const entitys = native_tools.EntitysSort(player.dimension, options, onSort, onFilter);
    entitys.forEach(entity => entity.addEffect('instant_health', 1, { amplifier: 2, showParticles: false }));
    if (!player.isInWater)
        return;
    player.addEffect('conduit_power', 300, { showParticles: false });
    const fish = native_tools.TrySpawnEntity(player.dimension, 'entity_elemental:fish_of_pearl', player.location);
    if (fish instanceof Error)
        return;
    player.getDynamicPropertyIds().forEach(id => fish.setDynamicProperty(id, player.getDynamicProperty(id)));
    fish.setDynamicProperty('entity:improve', data_entity.max_experience);
    fish.setDynamicProperty('entity:contract_user', player.id);
    fish.setDynamicProperty('entity:unlock', true);
}
;
function MagicCrystalShield(player) {
    player.addEffect('absorption', 300, { amplifier: 8, showParticles: false });
    player.addEffect('resistance', 300, { amplifier: 2, showParticles: false });
}
;
function StarryNightBead(player, item, slot, equippable) {
    equippable?.setEquipment(slot, native_tools.AlterDurability(item, 1));
    player.addEffect('night_vision', 300, { showParticles: false });
    player.addEffect('haste', 300, { amplifier: 2, showParticles: false });
}
;
function PurpleGoldSoulJade(player, item, slot, equippable) {
    equippable?.setEquipment(slot, native_tools.AlterDurability(item, 1));
    player.addEffect('village_hero', 300, { showParticles: false });
    player.addEffect('trial_omen', 300, { showParticles: false });
}
;
function IceEssenceGem(player, item, slot, equippable) {
    equippable?.setEquipment(slot, native_tools.AlterDurability(item, 1));
    const options = {
        families: ['monster'],
        location: player.location,
        maxDistance: 24,
        closest: 8
    };
    const entitys = player.dimension.getEntities(options);
    player.addEffect('speed', 300, { amplifier: 2, showParticles: false });
    entitys.forEach(entity => entity.addEffect('slowness', 300, { amplifier: 4 }));
}
;
function AzureSeaTide(player, item, slot, equippable) {
    equippable?.setEquipment(slot, native_tools.AlterDurability(item, 1));
    player.addEffect('conduit_power', 300, { showParticles: false });
    player.addEffect('weaving', 300, { showParticles: false });
}
;
function ScarletFlameHeart(player, item, slot, equippable) {
    equippable?.setEquipment(slot, native_tools.AlterDurability(item, 1));
    player.addEffect('fire_resistance', 300, { showParticles: false });
    player.addEffect('strength', 300, { amplifier: 2, showParticles: false });
}
;
